import { stringify } from 'qs';
import request from '../utils/request';
import $ from 'jquery';

export async function searchStatistic(params) {
  return request('/api/spider/search/statistic', {
    method: 'POST',
    body: params,
  });
}

export async function searchNew7(params) {
  return request(`/api/spider/title.detail.taobao?${stringify(params)}`);
}

export async function queryAlimamaOrders(params) {
  return request(`/api/alimama/orders?${stringify(params)}`);
}

export async function queryAlimamaShops(params) {
  return request(`/api/alimama/shops?${stringify(params)}`);
}

export async function queryQumai(params) {
  return request(`/api/spider/daren.qumai.org/xin7.php?${stringify(params)}`);
}

export async function searchTaobaoShop(params) {
  return new Promise((resolve, reject) => {
    const urlStr = `https://s.taobao.com/api?sid=${params.user_number_id}&app=api&m=get_shop_card`;
    $.ajax({
      url: urlStr,
      type:'get',
      dataType:'jsonp',
      success: (data) => {
        resolve(data);
      },
      error:function(XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      }
    });
  });
}

export async function queryShopPools(params) {
  return request(`${location.origin}/jsons/shopPool.json`);
}